

const PRE_URL = 'http://127.0.0.1:3000/mock/126/ht';

// get('/sss', {a:1}).then(res=>console.log(res))  
export const get = (url, params={}) => {
    let targetUrl = PRE_URL + url;
    let str = '';
    for(let key in params){
        if(!str){
            str+=`?${key}=${params[key]}`
        }else{
            str+=`&${key}=${params[key]}`
        }
    }
    return fetch(targetUrl+str).then(res=>res.json())
}


// POST封装
export const post = (url, params = {}) => {
    return fetch(PRE_URL+url, {
        method: 'POST',
        headers:{
            "Content-Type": "application/json",
        },
        body: JSON.stringify(params)
    })
      .then(res=>res.json())
      .then(res=>{
        const { data } = res || {};
        // const { success, msg, data } = res || {};
        // if(!success){
        //     alert(msg);
        //     return;
        // }
        return data;
    })
}



export default {
    get,
    post
}